<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
	pageEncoding="ISO-8859-1"
	import="org.diysearch.interfaces.Product, org.diysearch.interfaces.Service, 
		org.diysearch.services.BaseExceptionService, org.diysearch.tools.BaseTool"%><%
	String action = request.getParameter("do");

	if (action == null || "".equals(action)) {
		action = "_default_";
	}

	action = action.replaceAll("\\/", ""); // replace slash
	Service svc = null;

	try {
		if (BaseTool.IOC_ENGINE.hasBean(action + "_AOP")) {
			svc = (Service) BaseTool.IOC_ENGINE.getBean(action + "_AOP");
		} else {
			if (BaseTool.IOC_ENGINE.hasBean(action)) {
				svc = (Service) BaseTool.IOC_ENGINE.getBean(action);
			} else {
				// this request is for a static page probably
				svc = (Service) BaseTool.IOC_ENGINE.getBean("displayPage");
			}
		}

		if (svc != null) {
			if (svc.isWriter()) {
				svc.setWriter(out);
			} else {
				svc.setOutputStream(response.getOutputStream());
			}
			svc.setRequest(request);
			svc.setResponse(response);
			Product p = svc.execute();
			response.setContentType(p.getContentType());
			p.print();
		} else {
			out.println("service was found to be null ("+action+")");
		}
	} catch (IllegalStateException ex) {
		// huh, these are stupid. lets just try again
		response.sendRedirect("/"+action);
	} catch (Exception ex) {
		BaseExceptionService errorSvc = (BaseExceptionService) BaseTool.IOC_ENGINE.getBean("error-service");
		errorSvc.setWriter(out);
		errorSvc.setRequest(request);
		errorSvc.setResponse(response);
		Product errorProd = errorSvc.execute(ex);
		errorProd.print();
	}
%>